package de.guidoludwig.jatt.google;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.imageio.ImageIO;

import org.json.JSONException;
import org.json.JSONObject;

public class GoogleImageInfo {
	private URL thumbURL;
	private URL url;
	private int width;
	private int height;
	private BufferedImage thumb;
	private BufferedImage image;

	public GoogleImageInfo(JSONObject json) throws JSONException,
			MalformedURLException {
		thumbURL = new URL(json.getString("tbUrl"));
		url = new URL(json.getString("url"));
		width = Integer.valueOf(json.getString("width"));
		height = Integer.valueOf(json.getString("height"));
	}

	public URL getThumbURL() {
		return thumbURL;
	}

	public URL getUrl() {
		return url;
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public BufferedImage getThumb() throws IOException {
		if (thumb == null) {
			thumb = ImageIO.read(thumbURL);
		}
		return thumb;
	}

	public BufferedImage getImage() throws IOException {
		if (image == null) {
			image = ImageIO.read(url);
		}
		return image;
	}

}